package cn.bblocks.common.i18n.config;


import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * <p>Project: bb-i18n - DataSourceConfig</p>
 * <p>描述：db配置</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/4/1 11:23
 * @Version 1.0
 * @since 8
 */
@ConditionalOnProperty(name = "spring.ex.i18n.db.url", matchIfMissing = false)
public class DataSourceConfig {


    @ConditionalOnMissingBean(name = "i18nDataSource")
    @Bean(name = "i18nDataSource")
    public DataSource i18nDataSource(I18nProperties i18nProperties) {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUrl(i18nProperties.getDb().getUrl());
        dataSource.setUsername(i18nProperties.getDb().getUsername());
        dataSource.setPassword(i18nProperties.getDb().getPassword());
        dataSource.setDriverClassName(i18nProperties.getDb().getDriverClassName());
        return dataSource;
    }


}
